package ncc.bs.query.service.impl;

import java.util.List;
import java.util.Map;

import nc.bs.dao.BaseDAO;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.pub.BusinessException;
import ncc.bs.query.service.IContrastQueryService;

public class ContrastQueryServiceImpl implements IContrastQueryService{
	private BaseDAO baseDAO;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> queryBaseDataContrastTables(String exsystemcode, String bdclass)
			throws BusinessException {
		if(exsystemcode == null || bdclass == null || "".equals(bdclass) || "".equals(exsystemcode)) {
			return null;
		}
		String sql = this.buildBaseDataContrastTables(exsystemcode, bdclass);
		Object obj = this.getBaseDAO().executeQuery(sql, new MapListProcessor());
		if(obj == null) return null;
		List<Map<String, Object>> results = (List<Map<String, Object>>)obj;
		return results;
	}
	
	/**
	 *  构建基础数据对照表查询sql
	 * @param exsystemcode  外部系统编码
	 * @param bdclass       基础数据档案类型classid
	 * @return
	 * @throws BusinessException
	 */
	protected String buildBaseDataContrastTables(String exsystemcode, String bdclass) throws BusinessException {
        String sql = " select  " +
                "    dzb.bdcode nccode,dzb.bdname ncname, " +
                "    dzb.exsysdes  sfname,dzb.exsysval sfcode " +
                " from xx_exsystem xe  " +
                " left join xx_bdcontra dzh on xe.pk_exsystem = dzh.exsystem " +
                " left join xx_bdcontra_b dzb on dzh.pk_contra = dzb.pk_contra " +
                " where 1 = 1 and xe.dr =  0 " +
                "    and dzh.dr = 0 and dzb.dr = 0  " +
                "    and  xe.exsystemcode = '" + exsystemcode + "'  " +
                "    and dzh.bdclass = '" + bdclass + "' ";
		return sql;
	}
	
	
	public BaseDAO getBaseDAO() {
		return baseDAO == null ? new BaseDAO() : baseDAO;
	}
	
}
